<?php
/**
 * Created by PhpStorm.
 * User: Administrator
 * Date: 2019/1/14
 * Time: 16:17
 */

namespace App\HttpController;


use App\Utility\MTool;
use think\Db;

class User extends AbstractBase
{


    public function getUserInfo()
    {


        $cols = ['id','username','user_nick','user_uuid','coin','headimg'];

        // tongji
        $this->db->where('id',$this->member_info['user_id']);
        $res = $this->db->getOne('user',$cols);
        $this->db->where('bet_result', 2);
        $this->db->where('user_id',$this->member_info['user_id']);
        $count = $this->db->getValue('bet_log','count(bl_id)');

        $this->db->where('bet_result',1);
        $this->db->where('user_id',$this->member_info['user_id']);
        $win_count = $this->db->getValue('bet_log','count(bl_id)');


        if (!empty($res)) {
            $res['coin'] = MTool::formatNumber($res['coin']);
            $return['user_info'] = $res;
            $return['battle_info'] = ['win' => $win_count, 'lost' => $count];
            $this->success($return,'success');
        } else {
            $this->error([], '用户不存在');
        }
    }
}